import VueRouter from 'vue-router'


const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}
Vue.use(VueRouter)
    /*  */
import home from '../components/home.vue'
import Brand from '../components/Brand.vue'
import productdetail from '../components/productdetail.vue'
import classification_right from '../components/classification_right.vue'
import classification from '../components/classification.vue'
import Chanidnel from '../components/Chanidnel.vue'
import topic from '../components/topic.vue'
import user from '../components/User.vue'
import ShoppingCart from '../pages/ShoppingCart.vue'
import Vue from 'vue'


const router = new VueRouter({
        routes: [{
                path: '/',
                redirect: '/home'
            },
            {
                path: '/home',
                component: home,
                meta: {
                    ifShowTabbar: true
                },
                /* 首页 */
            },
            {
                /* 品牌详情信息 */
                name: 'brand',
                path: '/Brand/:id',
                component: Brand
            },
            { /* 商品详细信息 */
                name: 'productdetail',
                path: '/productdetail/:id',
                component: productdetail
            },
            {
                name: 'category',
                path: '/category',
                component: classification,
                meta: {
                    ifShowTabbar: true
                },
                children: [{
                    path: '/',
                    redirect: '/classification_right',
                    meta: {
                        ifShowTabbar: true
                    }
                }, {
                    name: 'wy_right',
                    path: '/classification_right',
                    component: classification_right,
                    meta: {
                        ifShowTabbar: true
                    },
                    props($router) {
                        return {
                            id: $router.query.id,
                            name: $router.query.name,
                            goodsList: $router.query.goodsList
                        }
                    }
                }]
            },
            {
                path: '/topic',
                component: topic,
                /* 分页 */
                meta: {
                    ifShowTabbar: true
                },
            },
            {
                path: '/user',
                component: user,
                meta: {
                    ifShowTabbar: true
                }
            },
            {
                path: '/cart',
                component: ShoppingCart,
                meta: {
                    ifShowTabbar: true,
                    // islogin: true,
                }
            },
            {
                path: '/Chanidnel/:id',
                component: Chanidnel
            }
        ]
    })
    /* 
    router.beforeEach((to, from, next) => {
        if (to.meta.islogin) {
            JSON.parse(localStorage.getItem("userInfo")) == null ? next() : next();
        } else {
            next();
        }
    }) */


export default router;